package com.alibaba.middleware.hsf.guide.server.protocol;

import com.taobao.hsf.invocation.InvocationHandler;
import com.taobao.hsf.model.metadata.ServiceMetadata;
import com.taobao.hsf.protocol.AbstractDelegateProtocolInterceptor;
import com.taobao.hsf.protocol.ServiceURL;

import java.util.List;

/**
 * @author weipeng2k 2017年09月07日 下午15:58:20
 */
public class PrintProtocol extends AbstractDelegateProtocolInterceptor {

    @Override
    public List<ServiceURL> export(ServiceMetadata serviceMetadata, InvocationHandler invocationHandler) {
        try {
            return protocol.export(serviceMetadata, invocationHandler);
        } finally {
            System.out.println("EXPORT SERVICE: " + serviceMetadata.getUniqueName());
        }
    }

    @Override
    public void unexport(ServiceMetadata serviceMetadata) {
        try {
            protocol.unexport(serviceMetadata);
        } finally {
            System.out.println("UN-EXPORT SERVICE: " + serviceMetadata.getUniqueName());
        }
    }

    @Override
    public InvocationHandler refer(ServiceMetadata serviceMetadata) {
        try {
            return protocol.refer(serviceMetadata);
        } finally {
            System.out.println("REFER SERVICE: " + serviceMetadata.getUniqueName());
        }
    }

    @Override
    public void unrefer(ServiceMetadata serviceMetadata) {
        try {
            protocol.unrefer(serviceMetadata);
        } finally {
            System.out.println("UN-REFER SERVICE: " + serviceMetadata.getUniqueName());
        }
    }
}
